﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms.Design;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;


[ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.All)]
public class CheckboxToolStripMenuItem : ToolStripControlHost
{

    [RefreshProperties(RefreshProperties.All)]
    public CheckboxToolStripMenuItem()
        : base(new CheckBox())
    {
        CheckBoxControl.CheckedChanged += _CheckedChanged;
    }

   
    public CheckBox CheckBoxControl
    {
        get
        {
            return Control as CheckBox;
        }
    }

    protected override void OnSubscribeControlEvents(Control c)
    {
        base.OnSubscribeControlEvents(c);
        CheckBox checkBox = (CheckBox)c;
        checkBox.BackColor = Color.Transparent; //Lösung für Aussehen
    }

    protected override void OnUnsubscribeControlEvents(Control c)
    {
        base.OnUnsubscribeControlEvents(c);
        CheckBox checkBox = (CheckBox)c;
    }


    //Wrap event and property to container
    public event Checked_ChangedEventHandler Checked_Changed;
    public delegate void Checked_ChangedEventHandler(object sender, EventArgs e);
    //
    private void _CheckedChanged(object sender, EventArgs e)
    {
        if (Checked_Changed != null)
        {
            Checked_Changed(sender,e);
        }
    }
    
    //
    [DefaultValue(50), Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    public bool Checked
    {
        get { return (Control as CheckBox).Checked; }
        set { (Control as CheckBox).Checked = value; }
    }

}
